#!/bin/bash
# 
# File: query-remove-tunnel.sh
# Purpose: 根据端口kill进程
#

cd $(dirname "$0")
. ./common.sh

INSTALLDIR=$(cd "$(dirname "$0")"; pwd);
FILE=$INSTALLDIR/$config_dir/$1
KEY_WORD=$2
exitcode=1


if [ ! $FILE ] || [ ! $KEY_WORD ]; then
    warn '必须传入要搜索的文件和关键字';
    exitcode=1;
else
	if test -f $FILE; then
		num=`(grep -n $KEY_WORD= | awk '{print $1}' | cut -d : -f 1) < ${FILE}`
		if [ ! $num ]; then
			warn '没有'$KEY_WORD'相关结果';
			exitcode=0;
		else
			TMP_FILE=$confirmed_dir/tunnel.tmp;
			sed -e $num'd' < $FILE > $TMP_FILE;
			rm -rf $FILE;
			mv $TMP_FILE $FILE
			exitcode=0
			result '删除'$KEY_WORD'的行';
		fi
	else
		warn '文件不存在:'$FILE;
		exitcode=0;
	fi
	
fi

exit $exitcode

# eof

